﻿#ifndef _SPATIAL_GEODATASET_WORKCOMMANDMANAGER_H
#define _SPATIAL_GEODATASET_WORKCOMMANDMANAGER_H

#include "udatabase/dll_cfg.h"
#include "kernel/Referenced.h"

namespace FD{
	namespace Utility{
		namespace DB{
				///<summary>
				///工作命令管理器
				///</summary>
				class CWorkCommand;
				class FD_DB_Export CWorkCommandManager : public FD::Kernel::CReferenced
				{
				public:
					CWorkCommandManager();
					virtual ~CWorkCommandManager();

				public:
					/// <summary>
					/// 判断是否支持"重做"操作
					/// </summary>
					/// <param name=""></param>
					/// <returns>如果支持"重做"则返回true,反之则否</returns>
					
					bool canRedo() const;
					/// <summary>
					/// 判断是否支持"回退"操作
					/// </summary>
					/// <param name=""></param>
					/// <returns>如果支持"回退"操作就返回true,反之则否</returns>
					
					bool canUndo() const;
					/// <summary>
					/// 获取操作数据的数量
					/// </summary>
					/// <param name=""></param>
					/// <returns>数量</returns>
					
					INT32 getCount() const;
					/// <summary>
					/// 获取指定索引处的操作数据
					/// </summary>
					/// <param name="index">索引</param>
					/// <returns>操作数据</returns>
					
					FD::Utility::DB::CWorkCommand * getCommand( UINT32 index );
					/// <summary>
					/// 获取回退次数
					/// </summary>
					/// <param name=""></param>
					/// <returns>次数</returns>
					
					INT32 getUndoLimit() const;
					/// <summary>
					/// 设置回退次数
					/// </summary>
					/// <param name="limit">次数限制</param>
					/// <returns></returns>
					
					void setUndoLimit( UINT32 limit );
					/// <summary>
					/// 执行重做
					/// </summary>
					/// <param name=""></param>
					/// <returns>操作数据</returns>
					
					FD::Utility::DB::CWorkCommand * redo();
					/// <summary>
					/// 执行回退
					/// </summary>
					/// <param name=""></param>
					/// <returns>操作数据</returns>
					
					FD::Utility::DB::CWorkCommand * undo();
					/// <summary>
					/// 开启编辑宏,即"组操作"
					/// </summary>
					/// <param name=""></param>
					/// <returns></returns>
					
					void beginMacro();
					/// <summary>
					/// 结束编辑宏,把在编辑宏中所做的所有操作合为一个操作,即最后一个操作
					/// </summary>
					/// <param name=""></param>
					/// <returns></returns>
					
					void endMacro();
					/// <summary>
					/// 检测是否在编辑宏中
					/// </summary>
					/// <param name=""></param>
					/// <returns>如果是,则返回true,反之则否</returns>
					
					bool isInMacro() const;
					/// <summary>
					/// 废弃编辑宏,即在编辑宏中的所有操作都清除掉
					/// </summary>
					/// <param name=""></param>
					/// <returns></returns>
					
					void abortMacro();
					/// <summary>
					/// 获取当前的编辑索引
					/// </summary>
					/// <param name=""></param>
					/// <returns>索引</returns>
					
					INT32 getCurrentIndex() const;
					/// <summary>
					/// 添加一个操作命令
					/// </summary>
					/// <param name=""></param>
					/// <returns></returns>
					
					FD::Utility::DB::CWorkCommand * push();
					/// <summary>
					/// 清空所有的操作命令
					/// </summary>
					/// <param name=""></param>
					/// <returns></returns>
					
					void clear();

				protected:
					void deleteCommands( INT32 beginIndex, INT32 endIndex );

					std::vector<FD::Utility::DB::CWorkCommand*> m_vecCommands;
					INT32 m_nLimit;
					INT32 m_nCurrentIndex;
					INT32 m_nMacroIndex;
					bool m_bBeginMacro;
				protected:
					C_DISABLE_COPY( CWorkCommandManager )
				};
			}
		}
	
}
#endif
